package cn.test;

import cn.cvs.dao.SysUserMapper;
import cn.cvs.pojo.TSysUser;
import cn.cvs.service.SysUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.Date;

import java.util.List;

public class Ch07SSM {
    @Test
    public void testCount(){

        String url_mybatis ="applicationContext_mybatis.xml";
       // String url_mvc ="applicationContext-mvc.xml";
        ApplicationContext context = new ClassPathXmlApplicationContext(url_mybatis);
//        SysUserMapper dao =context.getBean("userMapperImpl", SysUserMapper.class);
       // SysUserMapper dao =context.getBean(SysUserMapper.class);
        //System.out.println(dao.count());

        SysUserService userService = context.getBean(SysUserService.class);
       // System.out.println(userService.getUserList(new TSysUser()).size());
       // System.out.println(userService.login("admin","11111112"));


    }
    @Test
    public void testPage(){
        String url_mybatis ="applicationContext_mybatis.xml";
        ApplicationContext context = new ClassPathXmlApplicationContext(url_mybatis);
        SysUserService userService = context.getBean(SysUserService.class);

        // 分页只要5条数据
        PageHelper.startPage(1,5);// limit -5,5

        TSysUser param =new TSysUser();
        param.setRealName("li");
        param.setRoleId(2);
        List<TSysUser> userList= userService.getUserList(param);//获取到分页信息

        System.out.println(userList.size());
       // userList.forEach(user-> System.out.println(user));//获取到分页信息 --> 转换成Page对象  有 第几页, 共几页,总记录数

        PageInfo<TSysUser> page =new PageInfo<>(userList); //
        //共条 记录   /页
        System.out.println("共"+ page.getPages() + "页");
        System.out.println("共"+ page.getTotal() + "条");
        System.out.println("当前第"+ page.getPageNum() + "页");
        System.out.println("首页:"+ page.getNavigateFirstPage());
        System.out.println("尾页:"+ page.getNavigateLastPage());
        //Arrays  ---[]
        //ArrayList  ---集合
        System.out.println("页码数: "+ Arrays.toString( page.getNavigatepageNums()));
        System.out.println("数据列表: :" );
        page.getList().forEach(user-> System.out.println(user));

    }

    @Test
    public void now(){
        Date date =new Date();
        System.out.println(date);
    }
}
